package com.tyqx.hashchainbackend.controller.mongodb;

import com.mongodb.MongoClientURI;
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;
import com.mongodb.client.MongoDatabase;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.mongodb.core.MongoTemplate;

@Configuration
public class MongoConfig {

    @Bean
    public MongoClient mongoClient() {
        MongoClient mongoClient= MongoClients.create("mongodb://root:rootpassword@127.0.0.1:27017/hashchainMongo?authSource=admin&authMechanism=SCRAM-SHA-1");
        return mongoClient;
    }

    @Bean
    public MongoTemplate mongoTemplate() {
        return new MongoTemplate(mongoClient(), "hashchainMongo");
    }

    @Bean
    public MongoDatabase mongoDatabase(){
        com.mongodb.MongoClient mongoClient = new com.mongodb.MongoClient(new MongoClientURI("mongodb://root:rootpassword@127.0.0.1:27017/hashchainMongo?authSource=admin&authMechanism=SCRAM-SHA-1"));

        MongoDatabase myDatabase = mongoClient.getDatabase("hashchainMongo");
        return myDatabase;
    }



}
